package com.atstudy.headline.web.admin.controller.advertisement.adImpressions;

import com.atstudy.headline.entity.AdCreatives;
import com.atstudy.headline.entity.AdImpressions;
import com.atstudy.headline.entity.AdPerformanceDaily;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.AdImpressionsService;
import com.atstudy.headline.web.admin.vo.ad.AdImpressionVo;
import com.atstudy.headline.web.admin.vo.ad.AdPerDailyVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/adImpression")
public class AdImpressionController {
    @Autowired
    private AdImpressionsService adImpressionsService;
    @RequestMapping("/page")
    public Result<IPage<AdImpressions>> pageDictInfo(
            @RequestParam Integer current,
            @RequestParam Integer size,
            AdImpressionVo queryVo) {
        Page<AdImpressions> page = new Page<>(current, size);

        QueryWrapper<AdImpressions> wrapper = new QueryWrapper<>();
        if(queryVo!=null){
            wrapper.like("contentTitle",queryVo.getContentTitle());
            wrapper.like("creativeTitle",queryVo.getCreativeTitle());
            wrapper.eq("position_code",queryVo.getPositionCode());
        }
        IPage<AdImpressions> impressionsPage = adImpressionsService.pageInfo(page,queryVo);
        return Result.ok(impressionsPage);
    }

    /**
     * 删除
     * @param impressionId
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer impressionId){
        adImpressionsService.removeById(impressionId);
        return Result.ok();
    }

    /**
     * 批量删除
     * @param impressionIds
     * @return
     */
    @PostMapping("/deleteSelect")
    public Result deleteSelect(@RequestBody List<Integer> impressionIds) {
        adImpressionsService.removeByIds(impressionIds);
        return Result.ok();
    }
}
